{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f57a900b-9bb9-488c-8809-f507685d992e",
   "metadata": {},
   "source": [
    "# Groupby with Widget\n",
    "\n",
    "An interactive scatter plot of penguins grouped by island. When `groupby` is set a widget (or multiple if `groupby` is set to a list of variables) is displayed and updating its value re-renders the plot showing another slice of the dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58abdf72-4a03-4aa1-891f-8af3f7c332c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "\n",
    "df = hvplot.sampledata.penguins(\"pandas\").dropna()\n",
    "\n",
    "df.hvplot.scatter(\n",
    "    x='bill_length_mm',\n",
    "    y='flipper_length_mm',\n",
    "    color='sex',\n",
    "    groupby='island',\n",
    "    title='Penguins size by Sex',\n",
    "    xlabel='Bill Length (mm)',\n",
    "    ylabel='Flipper Length (mm)',\n",
    "    dynamic=False,\n",
    "    framewise=False,\n",
    "    frame_width=300,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f3782e01-7c7e-48d8-bb92-8d95608009f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "hvplot.extension('matplotlib')\n",
    "\n",
    "df = hvplot.sampledata.penguins('pandas').dropna()\n",
    "\n",
    "df.hvplot.scatter(\n",
    "    x='bill_length_mm',\n",
    "    y='flipper_length_mm',\n",
    "    color='sex',\n",
    "    groupby='island',\n",
    "    title='Penguins size by Sex',\n",
    "    xlabel='Bill Length (mm)',\n",
    "    ylabel='Flipper Length (mm)',\n",
    "    dynamic=False,\n",
    "    framewise=False,\n",
    "    width=200,\n",
    "    height=200,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d8487b1-93de-4214-8968-3983a2666103",
   "metadata": {},
   "source": [
    ":::{seealso}\n",
    "- [Groupby Option](option-groupby).\n",
    ":::"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
